﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ef.Repository.Infrastructure
{
    public class UnitOfWork : IUnitOfWork
    {
        private readonly IDatabaseFactory databaseFactory;
        private MyContext myContext;

        public UnitOfWork(IDatabaseFactory databaseFactory)
        {
            this.databaseFactory = databaseFactory;
        }

        private MyContext DbContext
        {
            get
            {
                return myContext ?? databaseFactory.GetContext();
            }
        }

        public void SaveChanges()
        {
            DbContext.SaveChanges();
        }
    }
}
